/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs';

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD';

export function formatToDateTime(date: dayjs.Dayjs | undefined = undefined, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format);
}

export function formatToDate(date: dayjs.Dayjs | undefined = undefined, format = DATE_FORMAT): string {
  return dayjs(date).format(format);
}

export function formatToDateTimeAndWeek(date:Date | undefined = undefined){
   date = date || new Date();
  var time
  let year = date.getFullYear(); // 年
  let month = date.getMonth() + 1; // 月
  let day = date.getDate(); // 日
  let week = date.getDay(); // 星期
  let weekArr = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六",
  ];
  let hour = date.getHours(); // 时
  let minute = date.getMinutes(); // 分
  let second = date.getSeconds(); // 秒
  return  `${year}-${month}-${day} ${(hour < 10 ? "0" + hour : hour)}:${(minute < 10 ? "0" + minute : minute)}:${(second < 10 ? "0" + second : second)} ${weekArr[week]}`
//console.log(time) // 2022/12/30 15:12:14 星期五
}

export const dateUtil = dayjs;
